/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ru.vsu.cs.piit.vokod.model;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author Галчонок
 */
@Entity
@Table(name = "diagnosis")
@NamedQueries({@NamedQuery(name = "Diagnos.findAll", query = "SELECT d FROM Diagnos d"),
@NamedQuery(name = "Diagnos.findByDiagnosId", query = "SELECT d FROM Diagnos d WHERE d.diagnosId = :diagnosId"), @NamedQuery(name = "Diagnos.findByCode", query = "SELECT d FROM Diagnos d WHERE d.code = :code")})
public class Diagnos implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "diagnos_id")
    private Integer diagnosId;
    @Column(name = "code")
    private String code;

    @JoinColumn(name = "group_of_diagnosis_id", referencedColumnName = "group_of_diagnosis_id")
    @ManyToOne(optional = false)
    private GroupOfDiagnosis groupOfDiagnosis;

//    @OneToMany(cascade = CascadeType.ALL, mappedBy = "diagnos", fetch = FetchType.LAZY)
//    private List<Pacient> pacientsCollection;

    public Diagnos() {
    }

    public Diagnos(Integer diagnosId) {
        this.diagnosId = diagnosId;
    }

    public Integer getDiagnosId() {
        return diagnosId;
    }

    public void setDiagnosId(Integer diagnosId) {
        this.diagnosId = diagnosId;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public GroupOfDiagnosis getGroupOfDiagnos() {
        return groupOfDiagnosis;
    }

    public void setGroupOfDiagnos(GroupOfDiagnosis groupOfDiagnos) {
        this.groupOfDiagnosis = groupOfDiagnos;
    }

//    public List<Pacient> getPacientCollection() {
//        return pacientsCollection;
//    }
//
//    public void setPacientCollection(List<Pacient> pacientsCollection) {
//        this.pacientsCollection = pacientsCollection;
//    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (diagnosId != null ? diagnosId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Diagnos)) {
            return false;
        }
        Diagnos other = (Diagnos) object;
        if ((this.diagnosId == null && other.diagnosId != null) || (this.diagnosId != null && !this.diagnosId.equals(other.diagnosId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return getCode();
    }

}
